﻿using System;
using System.Collections.Generic;
using System.Collections;
//using System.Linq;
using System.Text;

namespace DBSourceToolsLib.FileComparer
{

    public class DirectoryList
    {
        private string m_sourceDir;
        private string m_targetDir;
        private DCDirectory m_sourceDC;
        private DCDirectory m_targetDC;
        private List<IDCFileObject> m_sourceFiles = new List<IDCFileObject>();
        private List<IDCFileObject> m_targetFiles = new List<IDCFileObject>();
        private bool isBuildingSource = true;

        public List<IDCFileObject> SourceFiles
        {
            get { return m_sourceFiles; }
        }
        
        public List<IDCFileObject> TargetFiles
        {
            get { return m_targetFiles; }
        }
        
        public DirectoryList(string strSourceDir, string strTargetDir)
        {
            m_sourceDir = strSourceDir;
            m_targetDir = strTargetDir;
            BuildSourceTree();
        }

        private void BuildSourceTree()
        {

            this.m_sourceDC = new DCDirectory(m_sourceDir, m_sourceDir, this);
            //foreach (IDCFileObject oDCFileObject in m_sourceFiles)
            //{
            //    System.Console.WriteLine( (oDCFileObject.isFile() ? "S F " : "S D ") + oDCFileObject.GetRelativeFileName());
            //}

            this.isBuildingSource = false;

            this.m_targetDC = new DCDirectory(m_targetDir, m_targetDir, this);
            //foreach (IDCFileObject oDCFileObject in m_targetFiles)
            //{
            //    System.Console.WriteLine((oDCFileObject.isFile() ? "T F " : "T D ") + oDCFileObject.GetRelativeFileName());
            //}
            
        }

        internal void AddDCFileObject(IDCFileObject oDCFileObject)
        {
            if (!String.IsNullOrEmpty(oDCFileObject.GetRelativeFileName()))
            {
                if (isBuildingSource)
                    this.m_sourceFiles.Add(oDCFileObject);
                else
                    this.m_targetFiles.Add(oDCFileObject);
            }
        }

        public string GetSourceString()
        {
            StringBuilder oBuilder = new StringBuilder();
            foreach (IDCFileObject oDCFileObject in m_sourceFiles)
            {
                oBuilder.AppendLine(oDCFileObject.GetRelativeFileName());
            }

            return oBuilder.ToString();
        }

        public string GetTargetString()
        {
            StringBuilder oBuilder = new StringBuilder();
            foreach (IDCFileObject oDCFileObject in m_targetFiles)
            {
                oBuilder.AppendLine(oDCFileObject.GetRelativeFileName());
            }

            return oBuilder.ToString();
        }

    }
}
